package com.mes.service.manu;

import com.yy.base.common.dao.Dao;
import com.yy.base.common.service.BaseService;
import com.yy.base.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class TypesettingService extends BaseService {
	@Autowired
	private Dao dao;


	/**
	 * 获取排版历史记录
	 * @param product
	 * @param color
	 * @return
	 */
	public List<Map<String, Object>> getJobPaibanList( String product, String color) {
		String sql = "SELECT  " +
				"  jp.emeso_job_paiban_id ID,  " +
				"  jp.code pbCode,  " +
				"  P.  " +
				"VALUE  " +
				"  || ' - ' || P.NAME product,  " +
				"  c.emes_color_id colorId,  " +
				"  C.code || ' - ' || C.NAME COLOR ,  " +
				"  ( case jp.status when 'CREATE' then '创建'  when 'OK' then '完成' else '' end ) status " +
				"FROM  " +
				"  m_product P,  " +
				"  emes_color C,  " +
				"  emeso_job_paiban jp   " +
				"WHERE  " +
				"  P.m_product_id = jp.m_product_id   " +
				"  AND C.emes_color_id = jp.emes_color_id ";

		List params = new ArrayList();
		if (!StringUtil.isEmpty(color)) {
			sql += " and jp.emes_color_id = ?";
			params.add(color);
		}
		if (!StringUtil.isEmpty(product)) {
			sql += " and (p.name like ? or p.value like ?)";
			params.add("%" + product + "%");
			params.add("%" + product + "%");
		}
		return dao.query(sql + "  order by jp.created desc, jp.emeso_job_paiban_id", params.toArray());
	}
}